<template>
  <a-modal
    :title="`审核`"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="
      () => {
        $emit('ok')
      }
    "
    @cancel="
      () => {
        $emit('cancel')
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form" :labelCol="{ sm: { span: 4 } }" :wrapperCol="{ sm: { span: 20 } }" :selfUpdate="true">
        <!-- 检查是否有 id 并且大于0，大于0是修改。其他是新增，新增不显示主键ID -->
        <a-form-item label="名称">
          <a-input v-decorator="['name', { initialValue: 0 }]" disabled />
        </a-form-item>
        <!-- <a-form-item label="名称">
          <a-input
            v-decorator="['name', { rules: [{ required: true, message: '名称不能为空' }] }]"
            placeholder="请输入用户名称"
          />
        </a-form-item> -->
        <a-form-item label="审核结果">
          <a-select 
            @change="handleChange" 
            placeholder="请选择审核结果" 
            v-decorator="['status', { rules: [{ required: true, message: '审核结果不能为空' }] }]"
          >
            <a-select-option value="1">通过</a-select-option>
            <a-select-option value="3">驳回</a-select-option>
          </a-select>
        </a-form-item>
        <!-- <a-form-item label="三方模板ID" v-if="status == 1">
          <a-input
            v-decorator="['thirdTemplateId', { rules: [{ required: true, message: '三方模板ID不能为空' }] }]"
            placeholder="请输入三方模板ID"
          />
        </a-form-item> -->
        <a-form-item label="驳回理由" v-if="status == 3">
          <a-textarea
            v-decorator="['refuseReason']"
            placeholder="请输入驳回理由"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from 'lodash.pick'
import cloneDeep from 'lodash.clonedeep'
// 表单字段
const fields = ['name']

export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
  },
  data() {
    return {
      form: this.$form.createForm(this),
      status: null,
    }
  },
  components: {
  },
  created() {
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', (n) => {
      if(this.model){
        this.form.setFieldsValue(pick(this.model, fields))
        
      }
    })
  },
  methods: {
    handleChange(value) {
      this.status = value
    },
    
  },
  computed: {
   
  },
  watch: {
  },
}
</script>
